import Taro from '@tarojs/taro'

type keyName = 'openid' | 'token' | 'customerId' | 'customerName' | 'goodsShareId'

/**
 *
 * @param k key name
 * @returns 不存在返回空字符串
 */
export function getStorage(k: keyName): '' | string {
  return Taro.getStorageSync(k)
}

export function setStorage(k: keyName, value) {
  Taro.setStorageSync(k, value)
}

export function removeStorage(k: keyName) {
  Taro.removeStorageSync(k)
}

export function saveAfterSuccessfulLogin(resData: {
  token: string
  customer_id: string
  customer_name: string
}) {
  setStorage('token', resData.token)
  setStorage('customerId', resData.customer_id)
  setStorage('customerName', resData.customer_name)
}
